package javalaoniu.gitee.io.demo.logback.entity.comm;


import java.io.Serializable;

public class AppResp<T> implements Serializable {

    private static final long serialVersionUID = 1L;
    public static final int SUCCESS = 2000;
    public static final String SUCCESS_MSG = "success";
    public static final int FAILURE = -1;
    public static final String FAILURE_MSG = "fail";


    private int code;

    private String msg;

    private T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <T> AppResp<T> success() {
        AppResp<T> entity = new AppResp<>();
        entity.setCode(SUCCESS);
        entity.setMsg(SUCCESS_MSG);
        return entity;
    }

    public static <T> AppResp<T> success(T data) {
        AppResp<T> entity = success();
        entity.setData(data);
        entity.setMsg(SUCCESS_MSG);
        return entity;
    }

    public static <T> AppResp<T> error(String message) {
        AppResp<T> entity = new AppResp<>();
        entity.setCode(FAILURE);
        entity.setMsg(message);
        return entity;
    }
}